package com.Lgwd.service.userService.userImpl;

import com.Lgwd.entity.InitializeProfessionEntiy;
import com.Lgwd.entity.UserAccountEntiy;
import com.Lgwd.entity.UserEntiy;
import com.Lgwd.repository.InitializeProfessionRepository;
import com.Lgwd.repository.UserRepository;
import com.Lgwd.service.userService.InitializeProfessionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 角色信息初始化
 */
@Slf4j
@Service
public class InitializeProfessionServiceImpl implements InitializeProfessionService {


    @Autowired
    InitializeProfessionRepository initializeProfessionRepository;

    @Autowired
    UserRepository userRepository;

    /**
     * 根据注册的账号信息 生成角色信息
     * 查询初始角色信息
     * 信息拼接
     * @param userAccountEntiy
     * @return
     */
    @Override
    public void findProfessionInfo(UserAccountEntiy userAccountEntiy) {

        //根据职业查询初始属性
        InitializeProfessionEntiy info = initializeProfessionRepository.findByUser_profession(userAccountEntiy.getUser_profession());

        //初始属性录入user表 并且绑定角色账号
        UserEntiy userEntiy = new UserEntiy();
        userEntiy.setUser_account(userAccountEntiy.getUser_account());
        userEntiy.setUser_pwd(userAccountEntiy.getUser_pwd());
        BeanUtils.copyProperties(info,userEntiy);
        userRepository.save(userEntiy);

    }
}
